package d7_homework.d2_programmingquestions.thirddemo;

public class AtmServiceImpl implements AtmService{
    //初始化金额
    private static double account = 20000.0;
    @Override
    public void drawMoney(double money) throws RuntimeException {
        //进行取钱判断
        //利用卫语句进行判断
        if (money <= 0){
            throw new ATMRuntimeException("取款金额必须大于0");
        }
        if (money % 100 != 0){
            throw new ATMRuntimeException("取款金额必须是100的整数");
        }

        if (money > account){
            throw new ATMRuntimeException("余额不足,不能完成取款,请重新操作");
        }

        //对金额进行更新
        account -= money;

    }

    //进行展示余额
    @Override
    public double getBalance() {
        return account;
    }
}
